import Vue from 'vue'
import App from './App.vue'
import router from './router'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
// // 高德地图
// import "./plugins/aMap";
import VueAMap from 'vue-amap';

Vue.use(VueAMap);
VueAMap.initAMapApiLoader({
  plugin: ['AMap.Geolocation','AMap.Walking'],
  key: 'b18ea46cb51af68f2bca29c5600ab385',
  // plugin: ['AMap.Autocomplete', 'AMap.PlaceSearch', 'AMap.Scale', 'AMap.OverView', 'AMap.ToolBar', 'AMap.MapType', 'AMap.PolyEditor', 'AMap.CircleEditor'],
  // 默认高德 sdk 版本为 1.4.4
  v: '1.4.4'
});


import axios from 'axios';
let http=axios.create(); //创建一个axios的实例
//设置请求拦截
http.interceptors.request.use(
  config=>{
    console.log("发送请求之前执行");
    //从sessionstorage 拿出token，添加到请求中
    let token=window.sessionStorage.getItem("token");
    let refresh=window.sessionStorage.getItem("refresh");
    config.headers.authentication=token;
    config.headers.refresh=refresh;

    return config;
  }
);

//响应拦截器
http.interceptors.response.use(
 response=>{
    console.log("响应结束");
    let token= response.headers.authentication;
    let refresh= response.headers.refresh;
    if(token !=null || refresh!=null){
      // window.localStorage.setItem("token",token);
      window.sessionStorage.setItem("token",token);
      window.sessionStorage.setItem("refresh",refresh);
    }

    return response;

  }
);



Vue.prototype.$axios= http   //设置元属性




// Vue.prototype.$axios=axios
axios.defaults.withCredentials=true;


Vue.config.productionTip = false

Vue.use(ElementUI);

new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
